package com.st.springts.entity;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@Data
public class DepartmentDTO implements Serializable {
    private Long id;
    private String name;
    private String description;
    private List<DepartmentDTO> children;

    public DepartmentDTO() {
        this.children = new ArrayList<>();
    }

    public DepartmentDTO(Long id, String name, String description) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.children = new ArrayList<>();
    }

    public static DepartmentDTO fromEntity(Department department){
        DepartmentDTO dto =   new DepartmentDTO(department.getId(),department.getName(),department.getDescription());
       if(department.getChildren()!=null){
           for(Department child:department.getChildren()){
               dto.children.add(DepartmentDTO.fromEntity(child));
           }
       }
       return dto;
    }
}
